import request from '@/utils/request'

export function getArticleList(params) {
    return request({
        url: 'admin/articles',
        method: 'get',
        params
    })
}

export function getDraftsArticleList(params) {
    return request({
        url: 'admin/articles/drafts',
        method: 'get',
        params
    })
}

export function createArticle(data) {
    return request({
        url: 'admin/articles',
        method: 'post',
        data
    })
}

export function toggleArticleTop(id, isTop, topOrder) {
    return request({
        url: `admin/articles/${id}/top`,
        method: 'put',
        params: {
            isTop,
            topOrder: isTop ? (topOrder || 0) : undefined // 如果是取消置顶，不传权重值
        }
    })
}

export function toggleArticleHot(id, isHot, hotOrder) {
    return request({
        url: `admin/articles/${id}/hot`,
        method: 'put',
        params: {
            isHot,
            hotOrder: isHot ? (hotOrder || 0) : undefined
        }
    })
}

export function toggleArticleRecommend(id, isRecommend, recommendOrder) {
    return request({
        url: `admin/articles/${id}/recommend`,
        method: 'put',
        params: {
            isRecommend,
            recommendOrder: isRecommend ? (recommendOrder || 0) : undefined
        }
    })
}

export function updateArticle(id, data) {
    return request({
        url: `admin/articles/${id}`,
        method: 'put',
        data
    })
}

export function updateArticleOrder(id, data) {
    return request({
        url: `admin/articles/${id}`,
        method: 'put',
        data
    })
}

export function updateArticleStatus(id, data) {
    return request({
        url: `admin/articles/${id}/status`,
        method: 'put',
        data
    })
}

export function deleteArticle(id) {
    return request({
        url: `admin/articles/${id}`,
        method: 'delete'
    })
}

export function getArticleEdit(id) {
    return request({
        url: `admin/articles/edit/${id}`,
        method: 'get'
    })
}

export function updateArticlesSource(data) {
    return request({
        url: `admin/articles/batch/source`,
        method: 'put',
        data
    })
}

export function updateArticlesStatus(data) {
    return request({
        url: `admin/articles/batch/status`,
        method: 'put',
        data
    })
}

export function batchRemove(ids) {
    return request({
        url: `admin/articles/batch`,
        method: 'delete',
        data: { ids }
    })
}

export function batchArticlesTop(data) {
    return request({
        url: `admin/articles//batch/top`,
        method: 'put',
        data
    })
}

export function batchArticlesHot(data) {
    return request({
        url: `admin/articles/batch/hot`,
        method: 'put',
        data
    })
}

export function batchArticlesRecommend(data) {
    return request({
        url: `admin/articles/batch/recommend`,
        method: 'put',
        data
    })
}

export function getArticlePreview(id) {
    return request({
        url: `admin/articles/preview/${id}`,
        method: 'get'
    })
}
